<?php
/**
 * 前台预售商品
 *
 *
 *
 * * @网店运维 (c) 2015-2018  Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */



defined('InShopNC') or exit('Access Invalid!');
class presaleControl extends BaseHomeControl {
    public function indexOp(){
        Language::read('home_index_index');
        Tpl::output('index_sign','presale');

        //专题广告
        $model_ztadv = Model("ztadv");
        $top_adv_list = $model_ztadv->getAdvList(array('style'=>5,'state'=>1,'place'=>1,'start_time'=>array('lt',time()),'end_time'=>array('gt',time())),4);
        Tpl::output('adv_list',$top_adv_list);

        $slider_list = $model_ztadv->getAdvList(array('style'=>5,'state'=>1,'place'=>2,'start_time'=>array('lt',time()),'end_time'=>array('gt',time())),2);
        Tpl::output('slider_list',$slider_list);

        $model_activity = Model('activity');
        $date_list = $model_activity->getDateList(array('activity_type'=>1,'activity_state'=>1));

        if(empty($_GET['date'])){
            $selected_date = $date_list[0];
        }else{
            $selected_date = (int)$_GET['date'];
        }
        Tpl::output("curdate",$selected_date);
        Tpl::output('date_list',$date_list);

        $list =  $model_activity->getList(array('activity_type'=>1,'activity_state'=>1,'activity_start_date'=>$selected_date));

        $model_brand = Model("b_promotion");
        $brands = $model_brand->getPromotion(array('place'=>array('gt',1),'status'=>1,'start_time'=>array('egt',strtotime("+1 day"))));

        Tpl::output('brands',$brands);
        Tpl::output('list',$list);
        Tpl::showpage('presale');
    }

    public function listOp(){
          $activity = Model("activity");
          $item = $activity->getJoinList(array('activity_id'=>(int)$_GET['activity_id']));
          redirect("index.php?act=goods&op=index&goods_id=".$item[0]['item_id']);
    }

    public function noticeOp(){
        $model_brand = Model("b_promotion");
        $lang   = Language::getLangContent();
        if (!$_SESSION['member_id']){
            redirect(urlLogin('login', 'index', array('ref_url' => request_uri())));
        }
        $brand = $model_brand->getBrand(array('brand_id'=>(int)$_GET['brand_id']));

        if(empty($brand)) {
            showMessage($lang['wrong_argument'], 'index.php?act=presale&op=index', 'html', 'error');
        }

        $result = 1;
        if($result){
            showMessage('订阅成功!', 'index.php?act=presale&op=index', 'html', 'error');
        }
    }
}